<template>
  <view class="viewport">
    <view class="header" :style="{ paddingTop: safeAreaInsets!.top + 'px' }">
      <view class="left icon-left" @tap="Onleft()"></view>
      <uni-title type="h1" align="center" title="智能助手" class="text"></uni-title>
    </view>
    <scroll-view enable-back-to-top scroll-y class="scroll">
      <uni-section :title="item.Title" type="line" padding v-for="item in data" :key="item.Title">
        <view
          v-for="calData in item.CalDatas"
          :key="calData.Content"
          :class="{ warn: calData.Type === 2, error: calData.Type === 3, gray: calData.Type == 1 }"
          >{{ calData.Content }}</view
        >
      </uni-section>
    </scroll-view>
  </view>
</template>
<script setup lang="ts">
import { CalAPI } from '@/services/job'
import { useMemberStore } from '@/stores'
import type { CalResponse, CalData } from '@/types/job'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { ref } from 'vue'

// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
// 获取会员信息
const memberStore = useMemberStore()
const data = ref<CalResponse[]>()
//返回
const Onleft = () => {
  uni.switchTab({ url: '/pages/Detail/Detail' })
}
const Refresh = async () => {
  if (memberStore.profile) {
    const res = await CalAPI({
      Auth: memberStore.profile.Token,
      UserGroup: memberStore.profile.UserGroup,
    })
    data.value = res.result
  } else {
    uni.showToast({ icon: 'none', title: '请先登录' })
    setTimeout(() => {
      // 页面跳转
      uni.switchTab({ url: '/pages/my/my' })
    }, 500)
  }
}
onShow(async () => {
  await Refresh()
})
//初始化
onLoad(async () => {
  await Refresh()
})
</script>

<style lang="scss">
@import './styles/Smart.scss';
</style>
